home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / uniforth.zip / UNIFORTH.DOC < prev    next >
Text File  |  1985-08-20  |  87KB  |  2,446 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                               THE UNIFORTH SAMPLER
  9.  
  10.  
  11.  
  12.              The  UNIFORTH  Sampler is a subset of the full  Professional 
  13.         UNIFORTH.   It  provides  a  full  assembler,  video  editor  and 
  14.         software  floating-point arithmetic.   It supports  the  FORTH-83 
  15.         Standard  with few exceptions.   You will find the Sampler to  be 
  16.         the equivalent of several commercial systems selling for $200  or 
  17.         more.
  18.  
  19.              We decided to release the Sampler into the public domain for 
  20.         several reasons.   First, distributing a version of UNIFORTH that 
  21.         is  useful,  inexpensive  and  reproducible is  a  cost-effective 
  22.         method  of advertising.   Second,  it gives you a chance to try a 
  23.         good FORTH system at no cost.   If you don't like it, you haven't 
  24.         spent a dime.   If you do like it,  we ask (but don't demand!)  a 
  25.         $25  donation,  most  of  which  will be  reinvested  in  product 
  26.         development  to  improve both the Sampler and  the  Professional.  
  27.         Lastly,  the Sampler includes several novel features that we feel 
  28.         are  useful,   but  want  to  bring  before  the  community   for 
  29.         discussion.
  30.  
  31.              You  are  encouraged to copy and distribute the  Sampler  to 
  32.         your friends and local bulletin boards.   You may use the Sampler 
  33.         as the underlying language for a commercial software product.  In 
  34.         return,  we hope that you will consider us when you need a  full-
  35.         featured FORTH system or other options,  and that you will spread 
  36.         the word about UNIFORTH.
  37.  
  38.              We  can  supply  you  with the latest disk  version  of  the 
  39.         Sampler  in your 5 1/4" or 8" (CP/M) format for $35,  or you  can 
  40.         obtain a copy from a friend or local bulletin board.  Consult the 
  41.         order form at the end for more details.
  42.  
  43.              This  manual is a much-abbreviated edition of  the  UNIFORTH 
  44.         Manual Set.  (The complete set has over 500 pages, and comes in a 
  45.         custom  slipcase/binder.   Copies of the full set are $60.)  This 
  46.         manual  is  divided  into four  sections:   an  introduction  and 
  47.         advertisement  for the Professional;  a brief tutorial on  FORTH; 
  48.         some  of  the  system-specific  features  of  UNIFORTH;   and   a 
  49.         vocabulary list.
  50.  
  51.              The  UNIFORTH  Sampler  is NOT a supported  product  and  is 
  52.         distributed without warranties of Merchantability and fitness for 
  53.         a  particular  purpose.    If  you  need  support,  purchase  the 
  54.         Professional UNIFORTH.
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.         THE UNIFORTH SAMPLER                               Page 1-2
  69.  
  70.  
  71.         1.1  Getting Started
  72.  
  73.              The Sampler is distributed on one disk.  You can use the DOS 
  74.         utilities  COPY and DISKCOPY for backup and distribution  copies.  
  75.         You will find on the disk the following files:
  76.  
  77.              UNIFORTH.COM   The executable task image.
  78.  
  79.              FORTH.FTH      The default file that is opened when UNIFORTH 
  80.                             is executed.  It contains the SYSGEN utility, 
  81.                             the segment utility, a game and other stuff.
  82.  
  83.              VEDITOR.FTH    The configuration file for the video editor.
  84.  
  85.              UNIFORTH.DOC   This manual.
  86.  
  87.              WORDS.LST      The vocabulary word list.
  88.  
  89.              README.1ST     If   present,   additional  information  that 
  90.                             should be read before using the system.
  91.  
  92.         All  of  the features of UNIFORTH are preconfigured in  the  task 
  93.         image.   You  need not "load" anything to have a working  system.  
  94.         UNIFORTH.COM requires a minimum of 40Kb user space,  which  means 
  95.         that  you  may be tight if running on a 64Kb machine  with  DOS2.  
  96.         The Sampler will ONLY work with DOS2, and will bomb if you try it 
  97.         with DOS1.  In addition, the terminal I/O assumes a good PC clone 
  98.         that  has  a  compatible BIOS ROM.   If you are  using  an  MSDOS 
  99.         machine  that is not a clone,  you need to make one patch  before 
  100.         bringing  the system up.   Use DEBUG and change the "81" hex byte 
  101.         that  follows  the  ASCII string IOBYTE  located  somewhere  near 
  102.         address 1E6A to a "12" hex.
  103.  
  104.              Now start the execution of UNIFORTH by entering
  105.  
  106.                   UNIFORTH
  107.  
  108.         at which time you should get the Sampler startup screen.   If the 
  109.         screen  is blank or your computer hangs up,  then your system  is 
  110.         not PC compatible and you need to make the patch described above, 
  111.         or  else you have insufficient memory.   If you get a message  to 
  112.         the  effect of a missing file and an inquiry about  creating  it, 
  113.         answer  "N"  and leave FORTH at the earliest  opportunity.   Then 
  114.         make sure FORTH.FTH is on the same disk as UNIFORTH.COM.
  115.  
  116.              After  you get the "ok" prompt,  you're  into  FORTH.   Then 
  117.         follow  the  tutorial or an introductory text,  and learn  FORTH.  
  118.  
  119.              There are three ways to exit UNIFORTH:  enter two successive 
  120.         control-C  keystrokes (which aborts);  enter the word END  (which 
  121.         has the same effect as the CTRL-C);  or enter BYE (which  flushes 
  122.         and closes files before exiting).
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.         THE UNIFORTH SAMPLER                               Page 1-1
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.                                    Chapter 2
  142.  
  143.                                    USING FORTH
  144.  
  145.  
  146.              The  first  concept  to  understand in using  FORTH  is  the 
  147.         entering  and  execution  of words  through  the  terminal.   The 
  148.         general rules are:
  149.  
  150.  
  151.              1.   FORTH does not interpret a line of user input until the 
  152.                   user  terminates the line by entering a carriage return 
  153.                   (<cr>).
  154.  
  155.              2.   You  may  delete the previous character by  entering  a 
  156.                   backspace (ASCII 08) or delete (ASCII 127).   An  ASCII 
  157.                   "bell" character will be output if you try to backspace 
  158.                   past the beginning of the line.
  159.  
  160.              3.   You may delete an entire line by entering a CTRL-U (the 
  161.                   CTRL and U keys depressed simultaneously).
  162.  
  163.              4.   The user may interrupt printout at any time by entering 
  164.                   CTRL-S.    The  printout  is  resumed  when  CRTL-Q  is 
  165.                   pressed.  (Some systems permit any key for resumption.)
  166.  
  167.              5.   You  can  abort  a task that is  actively  printing  by 
  168.                   pressing the ESCAPE key.
  169.  
  170.         After pressing the return key to terminate a line of input, FORTH 
  171.         will  go  through the line and execute every "word" in the  input 
  172.         line.  The definition of a FORTH word is very simple:
  173.  
  174.                               <<<WORD DEFINITION>>>
  175.  
  176.                        A FORTH word is a sequence of up to
  177.                        64  characters,  with  at least one
  178.                        blank (space) on  each  side.   The
  179.                        sequence  of characters may contain
  180.                        any  character  in  the  ASCII  set
  181.                        except      control     characters.
  182.                        UNIFORTH  retains  the   first   31
  183.                        characters  and  the  length of the
  184.                        word;  any word with the  first  31
  185.                        characters and length identical are
  186.                        not   unique.    All   words   with
  187.                        identical  first  31 characters and
  188.                        lengths greater than or equal to 31
  189.                        characters     are    treated    as
  190.                        identical.
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.         USING FORTH                                             Page 2-2
  201.  
  202.  
  203.  
  204.  
  205.         For example, entering the line
  206.  
  207.                   OK 43 24 + LIST <cr>
  208.  
  209.         will cause FORTH to execute the four "words"
  210.  
  211.                   43         (push the number 43 on the stack)
  212.                   24         (push the number 24 on the stack)
  213.                   +          (add them together to get 67)
  214.                   LIST       (and then list block 67)
  215.  
  216.         Notice the spaces between the words on the input line.  You don't 
  217.         need to type spaces before the first word or after the last  one. 
  218.         The  words are executed in the order in which they were  entered. 
  219.         The actual execution of each word will be discussed later.
  220.  
  221.              If  all goes well and FORTH successfully executes each  word 
  222.         in the input line,  then FORTH will respond with its prompt (OK). 
  223.         If  an error occurs,  the name of the word it was executing  when 
  224.         the error occurred will be repeated, followed by a question mark.
  225.  
  226.  
  227.         2.1  The Stack
  228.  
  229.  
  230.              To  see  how  FORTH does such things as  manipulating  data, 
  231.         controlling  devices,  printing and accepting user's  input,  and 
  232.         managing  files,  you will have to understand the mechanism  that 
  233.         FORTH uses to keep track of the work in progress:  the STACK.
  234.  
  235.              A stack (sometimes called last-in-first-out or LIFO  memory) 
  236.         is  a  device used largely in  compiler  writing,  microprocessor 
  237.         design,  and HP calculators.  A stack can best be compared to the 
  238.         tray holders commonly used in cafeterias:  the type with a spring 
  239.         at  the bottom to push up trays as they are used.   Only the tray 
  240.         most recently added is accessable;  it must be removed before the
  241.         trays below it are available.  
  242.  
  243.              To see how this relates to FORTH, we need to experiment from 
  244.         a terminal.   If you type a carriage return,  FORTH will  respond 
  245.         with
  246.  
  247.                   OK  <cr>
  248.                   OK
  249.  
  250.         to  indicate that it has completed your previous request (in this 
  251.         case,  you requested nothing) and is ready to do  more.   Suppose 
  252.         you type a number:
  253.  
  254.                   OK  5 <cr>
  255.                   OK
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.         USING FORTH                                             Page 2-3
  267.  
  268.  
  269.         FORTH  has apparently done nothing;   however,  it has taken your 
  270.         number  (5),  interpreted it as the numeric value 5 (rather  than 
  271.         some other word), and "pushed" it onto the stack (added a tray to 
  272.         the holder).
  273.  
  274.              Suppose you type a series of numbers,  separated by at least 
  275.         one space so FORTH can tell them apart.   Basic FORTH only under-
  276.         stands 16-bit integers,  i.e.   numbers between -32768 and  32767 
  277.         with  no  decimal  points or other punctuation except  a  leading 
  278.         minus sign for negative numbers:
  279.  
  280.                   OK 4 1 2 7 -23 6 <cr>
  281.  
  282.         (We'll  tell  you  about other number types later.)  FORTH  still 
  283.         doesn't  seem to have done anything,  but the stack now  contains 
  284.         the original number 5,  plus 6 new numbers,  with the "top" value 
  285.         being the number 6.
  286.  
  287.              Obviously something is missing:   a method of removing  data 
  288.         from the stack and doing something useful with it.   The simplest 
  289.         thing  that  can be done with the stack is to see what's  on  top 
  290.         (easiest to get at).   FORTH has a word,  "." (dot),  which takes 
  291.         the  number  on the top of the stack,  prints its  value  on  the 
  292.         terminal,  and  throws the number away.   (We will enclose  FORTH 
  293.         words in quotes whenever confusion is possible).   For an example 
  294.         of dot:
  295.  
  296.                   OK 8 .  <cr>
  297.                   8
  298.                   OK
  299.  
  300.         will take the number 8,  push it on the stack,  then print it and 
  301.         prompt for more input.  Another example,
  302.  
  303.                   OK 8 7 .  CR .  <cr>
  304.                   7
  305.                   8
  306.                   OK 
  307.  
  308.         will type the two top stack values on separate lines.   CR is our 
  309.         second learned FORTH word:  it just outputs a carriage return and 
  310.         line feed to the terminal.
  311.  
  312.  
  313.         2.2  Stack Operators
  314.  
  315.  
  316.              So  far we can only get to the topmost stack value.   As  on 
  317.         the HP calculators,  there are words that allow us to  manipulate 
  318.         the stack to get at other values.   The table below lists some of 
  319.         the  most important operators.   For this and subsequent  tables, 
  320.         the topmost stack value is indicated by A,  the next stack  value 
  321.         by B,  and so on.   The table gives the word, its function, and a 
  322.         representation of the stack before and after the use of the word.
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.         USING FORTH                                             Page 2-4
  333.  
  334.  
  335.  
  336.              WORD          FUNCTION         BEFORE    AFTER
  337.              DUP        copies top of stack    B A     B A A
  338.              SWAP       reverses top two       B A     A B
  339.                         numbers on the stack
  340.              DROP       destroys top of stack  B A     B
  341.              OVER       copies 2nd number and  B A     B A B
  342.                          pushes it on top
  343.              ROT        moves 3rd num to top   C B A   B A C
  344.              -ROT       moves top to 3rd num   C B A   A C B
  345.  
  346.  
  347.              The  usefulness  of these stack manipulation  words  becomes 
  348.         apparent  when  you  consider  the  following  problem:   suppose 
  349.         someone  else  has  put  a number on the stack and  you  wish  to 
  350.         calculate its square without knowing what it is.  You could type
  351.  
  352.              OK  DUP * . <cr>
  353.              25
  354.              OK 
  355.  
  356.         By inference,  the number on the stack was 5.  Of course, we used 
  357.         a  word  not defined yet to multiply the two  values.   So  let's 
  358.         digress and discuss arithmetic functions.
  359.  
  360.  
  361.         2.3  Arithmetic Functions
  362.  
  363.  
  364.              All  arithmetic  functions act on the stack  with  a  method 
  365.         called  postfix or Reverse Polish Notation (RPN),  commonly  used 
  366.         with the HP calculators.  Rather than give extensive examples, we 
  367.         will  assume  that you have used an RPN calculator at some  time, 
  368.         and just give a table of the elementary functions.
  369.  
  370.              WORD       FUNCTION                BEFORE   AFTER
  371.              ABS       absolute value of top       B A    B |A|
  372.                        of stack
  373.              NEGATE    2's complement top          B A    B -A
  374.                        of stack
  375.              +         add top stack values        B A    B+A
  376.              -         sub top stack values        B A    B-A
  377.              *         mul top stack values        B A    B*A 
  378.              /         div top stack values        B A    B/A  
  379.              MOD       remainder of division     C B A    C R
  380.                        of B/A
  381.              MAX       top two numbers dropped,  C B A    C MAX(A,B)
  382.                        larger one put back
  383.              MIN       top two numbers dropped,  C B A    C MIN(A,B)
  384.                        smaller one put back
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.         USING FORTH                                             Page 2-5
  399.  
  400.  
  401.         An  example of the use of some of these functions is to  evaluate 
  402.         the expression
  403.  
  404.                                ABS [(5+4)/2 - 20]
  405.  
  406.         You would enter it with FORTH by
  407.  
  408.                   OK  5 4 + 2 / 20 - ABS . <cr>
  409.                   16
  410.                   OK
  411.  
  412.         Note  that  the division truncates because we are  using  integer 
  413.         arithmetic.
  414.  
  415.  
  416.         2.4  Logical Operators
  417.  
  418.  
  419.              The  logical  operators act upon all 16 of the  bits  in  an 
  420.         integer  and leave results which involve all those  bits.   There 
  421.         are  four basic operators,  three of which require two numbers on 
  422.         the stack and one which acts only on the top value:
  423.  
  424.                   NOT    one's complement of the top value.
  425.                   AND    bitwise "AND" of the top two values.
  426.                   OR     bitwise "OR" of the top two values.
  427.                   XOR    bitwise exclusive OR of the top two values.
  428.  
  429.  
  430.              The use of these definitions is most easily seen by using  a 
  431.         base which is a power of two.  The most common of these are octal 
  432.         and  hexadecimal.   This way there is an easily decoded relation-
  433.         ship  between  the value of a number and the state of  its  indi-
  434.         vidual bits.  Type
  435.  
  436.                   OCTAL <cr>
  437.  
  438.         FORTH is now ready to handle base 8.   Typing HEX would give base 
  439.         16,  and DECIMAL gives base 10.   Using base 8, an example of the 
  440.         logical operators is
  441.  
  442.                   OK 453 321 AND .  <cr>
  443.                   1
  444.                   OK
  445.  
  446.         where  the only bit in common between the octal numbers  453  and 
  447.         321 is the least significant bit.
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.         USING FORTH                                             Page 2-6
  465.  
  466.  
  467.         2.5  Relational Operators
  468.  
  469.  
  470.              Relational  operators  compare  stack  values  and  leave  a 
  471.         logical  truth flag;   ie.,  a number that is either zero or  one 
  472.         depending  on  the tested condition.   All  relational  operators 
  473.         destroy  the stack values they test and just leave the truth flag 
  474.         on  the  stack.   There  are  many  of  these  operators  because 
  475.         condition  testing is one of the most common functions  performed 
  476.         in FORTH.  The table below lists the major relational operators.
  477.  
  478.              WORD                   FUNCTION
  479.                0=       If the top stack value equals zero, leaves a 1
  480.                         (true);  otherwise, leaves a 0 (false).  Also
  481.                         called NOT.
  482.  
  483.                0<       True if stack value is less than 0, false
  484.                         otherwise.
  485.  
  486.                0>       True if stack value is greater than 0, false
  487.                         otherwise.
  488.  
  489.                <        True if the next lower stack value (B) is less
  490.                         than the top stack value (A), false otherwise.
  491.  
  492.                =        True if B is equal to A, false otherwise.
  493.  
  494.                >        True if B is greater than A, false otherwise.
  495.  
  496.  
  497.              An example of the use of some of these relational  operators 
  498.         is to compare
  499.  
  500.                   OK 8 0= 9 10 < = .  <cr>
  501.                   0
  502.                   OK 
  503.  
  504.         The  number 8 is compared to see if it is equal to zero.   It  is 
  505.         not, so this operation leaves a 0 on the stack in place of the 8. 
  506.         Then 9 is tested to see if it is less than 10.   This is true, so 
  507.         a 1 is pushed on the stack.  Then the results of the previous two 
  508.         operations  (0 and 1) are tested to see if they are  equal.   The 
  509.         result is 0, which is then printed.  The stack is now empty.
  510.  
  511.  
  512.         2.6  Forth Memory Allocation
  513.  
  514.  
  515.              Before we go any further in examining FORTH, a little of the 
  516.         nuts  and  bolts  must be presented.   FORTH is  a  core-resident 
  517.         program that occupies approximately 24000 bytes of  memory.   Not 
  518.         all of the allocated memory is filled under normal use;  instead, 
  519.         it  is  partitioned  into subsections that can  expand  with  the 
  520.         increasing load.  The partitions are:
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.         USING FORTH                                             Page 2-7
  531.  
  532.  
  533.  
  534.         I.   THE DICTIONARY.  Nearly all of FORTH resides in the diction-
  535.              ary.   The  dictionary  starts at about address 300  and  is 
  536.              composed of three contiguous sections:
  537.  
  538.              a.   Kernel.   Core locations 300 through 8000 (bytes)  hold 
  539.                   the  FORTH  kernel.   This  is  the  assembly  language 
  540.                   program  that  contains  the 190 most  primitive  FORTH 
  541.                   definitions; somewhat ignorant but easily teachable. 
  542.  
  543.              b.   Basic FORTH.   This section is the SYSTEM  definitions, 
  544.                   some  200  elementary words that later definitions  can 
  545.                   draw on.
  546.  
  547.              c.   Application  FORTH.   In this area are the  definitions 
  548.                   for any program or utility that you load after starting 
  549.                   your session.  This area grows upwards to higher memory 
  550.                   locations.
  551.  
  552.         II.  THE  DATA  STACK.   The data stack contains  such  items  as 
  553.              arguments passed between routines, numbers typed in from the 
  554.              terminal,  system word temporary storage,  etc.,  and is the  
  555.              stack we previously talked about.  This stack is placed near 
  556.              the  top of the FORTH program,  and "grows" downward towards 
  557.              lower memory locations.
  558.  
  559.         III. THE  RETURN STACK.   Less used by the  beginning  programmer 
  560.              (for  good  reason!),  the return stack's primary use is  to 
  561.              contain  addresses  of  the words to  be  executed  when  we 
  562.              "return" from the word being currently executed.  Other uses 
  563.              include  storage for loop parameters,  and numbers that  are 
  564.              "in  the  way" on the data stack.   The return stack  starts 
  565.              near the top of the memory allocation and grows downward  in 
  566.              memory.  It is much smaller than the data stack (only 80 16-
  567.              bit  locations),  so  use  it  sparingly  and  with  careful 
  568.              attention to the protocol.
  569.  
  570.         IV.  THE BLOCK BUFFERS.  UNIFORTH is a disk-based system and uses 
  571.              two  or  more  buffers to bring data to and from  the  disk.  
  572.              Each buffer is nominally 1024 bytes long.
  573.  
  574.         The  addresses  listed above are for a Z80  CP/M  system.   Other 
  575.         systems will have slightly different addresses.
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.         USING FORTH                                             Page 2-8
  597.  
  598.  
  599.              A diagram of how memory is allocated in core is shown below.
  600.  
  601.              high limit     |---------------------------|
  602.                             |    block buffer 2         |
  603.                             |---------------------------|
  604.                             |    block buffer 1         |
  605.                             |---------------------------|
  606.                             | v                         |
  607.                             | v       return stack      |
  608.                             | v                         |
  609.                             |---------------------------|
  610.                             | v                         |
  611.                             | v        data stack       |
  612.                             | v                         |
  613.                         ^   |   .   .   .   .   .   .   |
  614.                         ^   |                           |
  615.                         ^   |                           |
  616.               memory    ^   |   .   .   .   .   .   .   |
  617.              addresses  ^   | ^                         |
  618.                         ^   | ^ user application        |
  619.                         ^   | ^  dictionary             |
  620.                             | ^                         |
  621.                             |---------------------------|
  622.                             |                           |
  623.                             | "standard" FORTH          |
  624.                             |     dictionary            |
  625.                             |                           |
  626.                             |---------------------------|
  627.                             |                           |
  628.                             |    FORTH kernel           |
  629.                             |        dictionary         |
  630.                             |                           |
  631.              low limit      |---------------------------|
  632.  
  633.  
  634.  
  635.         2.7  Pointer Values
  636.  
  637.  
  638.              FORTH  has  four  "pointers,"  most  of  which  are  usually 
  639.         transparent  to the user.   The two stack pointers  have  already 
  640.         been mentioned.   The data stack pointer can be referenced by the 
  641.         word  SP@,  which  indicates the address of the top of the  stack 
  642.         before  SP@ was used.   The return stack pointer's current  value 
  643.         can be obtained by the word RP@.
  644.  
  645.              The dictionary pointer (DP) indicates the first free  memory 
  646.         address  for  the storage of new definitions.   Its value can  be 
  647.         obtained by DP @ and can be changed by ALLOT,  which uses the top 
  648.         stack  value  as the number of bytes by which  to  increment  the 
  649.         pointer.   Further  explanation of the dictionary pointer can  be 
  650.         found in the User's Guide.
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.         USING FORTH                                             Page 2-9
  663.  
  664.  
  665.              The   interpreter  pointer  (IP)  is  an  internal  register 
  666.         containing  the address of the next FORTH "word" to be  executed. 
  667.         It  cannot  be accessed by the programmer  except  with  assembly 
  668.         language  routines.   Some further information concerning the  IP 
  669.         can be found in the User's Guide.
  670.  
  671.  
  672.         2.8  Definitions
  673.  
  674.  
  675.              Now let's get back to our problem of squaring numbers.  What 
  676.         we discussed before leads into the next logical point:   it would 
  677.         be   convenient  to  take  a  series  of  stack  operations   and 
  678.         automatically call in the whole series when needed.  Consider the 
  679.         case of squaring a number, i.e., calculating A*A.
  680.  
  681.              You can define a word to perform this function for you. Pick 
  682.         a name for your word,  for example,  SQUARE.  You can define this 
  683.         word by
  684.  
  685.                   OK : SQUARE DUP * ;  <cr>
  686.  
  687.  
  688.              The  first  thing  on the line is a word which is  just  the 
  689.         single  character  ":" (colon).   Following it (separated  by  at 
  690.         least one space) is the word name you are defining.   Next is the 
  691.         series of words you wish to have executed (DUP *).   Finally, the 
  692.         closing word is a semicolon,  which indicates that the definition 
  693.         of SQUARE is complete.   The word,  once defined, can now be used 
  694.         like any of the well-known words, i.e.
  695.  
  696.                   OK 5 SQUARE . <cr>
  697.                   25
  698.                   OK 3 4 + SQUARE 40 - . <cr>
  699.                   9
  700.                   OK
  701.  
  702.  
  703.              Before  proceeding,  you  should stop and consider  what  is 
  704.         happening  in  more detail.   The process of putting a series  of 
  705.         words  together  in  a so-called  "colon  definition"  is  called 
  706.         "compilation".   When  FORTH  is  processing the words  inside  a 
  707.         definition,  it  does almost all the work needed to perform  your 
  708.         function.   When the word is used, FORTH can very rapidly perform 
  709.         the function you have designed.
  710.  
  711.              The  colon  starts  the compilation  process  by  using  the 
  712.         following  character  string  as  the "name"  of  what  is  being 
  713.         compiled.   The name is stored at the beginning of the definition 
  714.         in  the  "header section" as a count byte followed by  the  ASCII 
  715.         characters  of  the name.   The address of an  assembly  language 
  716.         routine  is next (the "code section") and then the information to 
  717.         be processed (the "parameter section"),  such as the addresses of 
  718.         the FORTH words to be included in your definition.   Finally, the 
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.         USING FORTH                                             Page 2-10
  729.  
  730.  
  731.         semicolon turns off the compilation process and gets you back  to 
  732.         the "interactive execution" mode you started with.  If you forget 
  733.         the semicolon, any words you type after it will be thrown in with 
  734.         the colon definition and not executed immediately.
  735.  
  736.              Remember  that the only restriction on names is that control 
  737.         characters  are  not allowed.   There is nothing sacred  about  a 
  738.         "number" such as "7".  If you want to be different you can define
  739.  
  740.                   :  7 5 ;  
  741.  
  742.         and obtain such bizarre results as
  743.  
  744.                   OK 7 3 + .  <cr>
  745.                   8
  746.                   OK
  747.  
  748.  
  749.              The next step in defining words is to realize that there  is 
  750.         no   distinction   between  "FORTH  words"  and   "your   words". 
  751.         Previously, you defined the word
  752.  
  753.                   :  SQUARE DUP * ;  
  754.  
  755.         Using  this word you can define a routine to get the fifth  power 
  756.         of numbers like this:
  757.  
  758.                   :  **5 DUP SQUARE SQUARE * ;  
  759.  
  760.  
  761.              Now suppose you choose to redefine SQUARE.  You could choose 
  762.         to do this by typing
  763.  
  764.                   OK :  SQUARE DROP 5 .  ;  <cr> SQUARE Redefined 
  765.                   OK 7 SQUARE <cr>
  766.                   5
  767.                   OK
  768.  
  769.         Note the "Redefined" informative message that you get.   However, 
  770.         the  new  definition  of SQUARE will not affect its  use  in  the 
  771.         previously defined word, **5.
  772.  
  773.                   OK 2 **5 .  <cr>
  774.                   32
  775.                   OK
  776.  
  777.         But  if  **5 is now redefined,  the new definition of  SQUARE  is 
  778.         used.
  779.  
  780.                   OK :  **5 DUP SQUARE SQUARE * ;  <cr> **5 Redefined 
  781.                   OK 2 **5 .  <cr>
  782.                   5 5 2
  783.                   OK
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.         USING FORTH                                             Page 2-11
  795.  
  796.  
  797.  
  798.              The behavior is governed by these two rules:
  799.  
  800.              1.   When  you  define  a word,  all words used  within  the 
  801.                   definition must have been previously defined.
  802.  
  803.              2.   Later  changing a word you use within definitions  will 
  804.                   not  affect  words you have  already  defined  -- their 
  805.                   function  will  remain unchanged until you enter a  new 
  806.                   definition for the word.
  807.  
  808.  
  809.              Notice  that only the most recent dictionary  definition  of 
  810.         words used within a colon definition will be used.   For example, 
  811.         in   subsequent  use,   the  correct  definition  for  SQUARE  is 
  812.         inaccessible  because another definition for SQUARE  was  created 
  813.         later.   There  is  a  way of "forgetting" the later  version  of 
  814.         SQUARE.  The FORTH word FORGET, used like
  815.  
  816.                   OK FORGET SQUARE <cr>
  817.                   OK
  818.  
  819.         will erase from the dictionary the most recent definition of
  820.         SQUARE and all definitions made after it.
  821.  
  822.              We  have mentioned colon definitions.   You can also  define 
  823.         machine  language words with the word CODE,  and terminate  their 
  824.         definition with the word END-CODE,  in a similar manner as  colon 
  825.         and semicolon.  We will mention machine language routines in more 
  826.         detail in a subsequent chapter.
  827.  
  828.              One  other item before we leave the subject of  definitions. 
  829.         Besides using RPN representation, FORTH is decidedly not FORTRAN-
  830.         like   in  its  definitions.    Though  these  act  exactly  like 
  831.         subroutines, they differ in that most arguments are passed on the 
  832.         data   stack,   and  that  the  entire  definition   is   written 
  833.         horizontally.   While  you can write definitions with each called 
  834.         word  on a separate line,  it is not commonly done.   This can be 
  835.         confusing to the beginning programmer,  but think of it as if you 
  836.         were entering the line interactively.
  837.  
  838.  
  839.         2.9  Constants and Variables
  840.  
  841.  
  842.         FORTH  has several words for reading from and writing to  memory. 
  843.         To  read  from memory,  an address must be specified.   Then  "@" 
  844.         (pronounced "fetch") takes that address,  reads the 16-bit  value 
  845.         starting at that address,  and places it on the stack.   The word 
  846.         C@ accomplishes a similar task, except that it retrieves only the 
  847.         byte stored at the address, places it in the low byte of a 16-bit 
  848.         location or cell which is then placed on the stack.
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.         USING FORTH                                             Page 2-12
  861.  
  862.  
  863.                               <<<CELL DEFINITION>>>
  864.  
  865.                        A cell is a 16-bit memory location.
  866.                        The low order byte is stored at the
  867.                        first byte address;  the high order
  868.                        byte   is   stored   at   the  next
  869.                        consecutive byte address.
  870.  
  871.  
  872.         The  procedure  of  reading (or fetching as it is  more  commonly 
  873.         called)  and  then printing is used  often.   Therefore,  a  word 
  874.         exists that combines both of these operations--the question  mark 
  875.         (?).  It fetches an integer from a given address and prints it. 
  876.  
  877.              Two words exist to write into a specific memory location. As 
  878.         for  reading,  the  exclamation point ("!",  pronounced  "store") 
  879.         stores a 16-bit value and C!   stores the low-order byte of a 16-
  880.         bit  value from the top of the stack.   In both cases,  the  data 
  881.         value and the address are removed from the stack.  For example, 
  882.  
  883.                                   16432 18500 !
  884.  
  885.         stores the values 16432 at address 18500.
  886.  
  887.              Also in the context of definitions, you can define constants 
  888.         and variables to be used in your programs.  Numeric constants can 
  889.         be defined with the word CONSTANT.  For example,
  890.  
  891.                   31415 CONSTANT PI-TIMES-10000
  892.  
  893.         defines  the FORTH word PI-TIMES-10000.   Whenever you type  this 
  894.         word, the constant 31415 will be pushed on the stack.
  895.  
  896.              Often  you find that it is awkward to have all your data  on 
  897.         the  stack at once.   You can store data in single  named  memory 
  898.         locations with the FORTH word VARIABLE.  For example,
  899.  
  900.                   VARIABLE Q
  901.  
  902.         defines the word Q.   When you type Q, the address of the storage 
  903.         location corresponding to Q is pushed onto the stack.  You cannot 
  904.         preset  this storage location during the definition as you  could 
  905.         with  CONSTANT.   You can use Q in conjunction with @ and  !   to 
  906.         change  the  contents  during program  execution  (for  instance, 
  907.         updating a counter).   There is a special word called tick,  "'", 
  908.         which  allows  the  changing of the value of  a  CONSTANT.   Tick 
  909.         places the address of a word's parameter field (where the  number 
  910.         is  stored for CONSTANT) on the stack.   You can then change  the 
  911.         value using "store".  For example,
  912.  
  913.                   31416 ' PI-TIMES-10000 !
  914.  
  915.         changes PI-TIMES-10000 from 31415 to 31416.
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.         USING FORTH                                             Page 2-13
  927.  
  928.  
  929.  
  930.         2.10  Typing
  931.  
  932.  
  933.              One of the problems with FORTH as far as users are concerned 
  934.         is that there is no typing of variables.   That is, once you have 
  935.         defined  variable XXX,  the system doesn't know later whether XXX 
  936.         is an integer,  floating point number, or what.  The advantage of 
  937.         this  is  that  less  storage  space  and  compiler  overhead  is 
  938.         necessary,  and  as long as you are dealing with  characters  and 
  939.         integers, the inconvenience is small.
  940.  
  941.              The  disadvantage  comes into play when FORTH  becomes  more 
  942.         complicated,  and  you  start implementing types such  as  double 
  943.         precision integer,  string variables,  etc.  Because of this lack 
  944.         of typing, you cannot perform mixed-mode arithmetic automatically 
  945.         using a precedence scheme such as in FORTRAN.
  946.  
  947.              Therefore, when using FORTH, you must keep the type of every 
  948.         variable  and  stack  member in mind,  and  perform  the  correct 
  949.         operation on the numbers.  For example:
  950.  
  951.                 +      Add the two top 16-bit stack values, assuming they
  952.                        are single precision integers, and leave a 16-bit
  953.                        result.
  954.  
  955.                 D+     Add the four top 16-bit stack values, assuming
  956.                        they are two double precision (32-bit) integers,
  957.                        and leave a 32-bit result.
  958.  
  959.                 F+     Add the four top 16-bit stack values, assuming
  960.                        they are two single precision (32-bit) floating
  961.                        point values, and leave a 32-bit floating point
  962.                        result.
  963.  
  964.                 SS*D   Multiply the two top 16-bit stack values assuming
  965.                        they are single precision integers, and leave a
  966.                        32-bit double precision integer result.
  967.  
  968.         In  other  words,  some  of the work has been taken  out  of  the 
  969.         compiler  or language and placed on the  programmer's  shoulders. 
  970.         There  is  no  inherent  reason why  a  typed-FORTH  couldn't  be 
  971.         created;  there just has been no emphasis in this direction.
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.         USING FORTH                                             Page 2-14
  993.  
  994.  
  995.         2.11  Control Structures
  996.  
  997.  
  998.              Control   structures  allow  you  to  modify  program  flow, 
  999.         primarily by making decisions and causing various definitions  to 
  1000.         execute within a colon definition.  
  1001.  
  1002.  
  1003.         2.11.1  Looping
  1004.  
  1005.  
  1006.              Maintaining an iteration counter and causing a branch out of 
  1007.         the  loop  when a preset value is reached is a  very  fundamental 
  1008.         software feature.  FORTH provides the DO and LOOP words for this.
  1009.  
  1010.              When making a loop,  you usually know the starting value and 
  1011.         the number of repetitions desired.   When you sum these,  you get 
  1012.         the total.   DO expects to find two parameters on the stack,  the 
  1013.         total and the starting value:
  1014.  
  1015.              [total] [start] DO [things to be done] LOOP
  1016.  
  1017.  
  1018.              As an example, consider a definition to print out 5 numbers.  
  1019.         If we start with 1, then the total is 6, and our definition is:
  1020.  
  1021.                   :  PRINT_FIVE 6 1 DO .  LOOP ;  <cr>
  1022.  
  1023.         This definition expects to find 5 numbers on the stack.
  1024.  
  1025.                   OK 34 5 2 6 -3 PRINT_FIVE <cr>
  1026.                   -3 6 2 5 34
  1027.                   OK
  1028.  
  1029.              Other  languages use the starting value and the ending value 
  1030.         as the loop limits,  and switch the order of the  limits.   These 
  1031.         variances are  matters of preference.
  1032.  
  1033.              Often  it  is useful to have a word to access the  iteration 
  1034.         counter, and FORTH provides several of them as indicated below.
  1035.  
  1036.              WORD                    FUNCTION
  1037.              I           Push the value of the iteration counter of
  1038.                           the innermost loop onto the stack.
  1039.  
  1040.              J           Push the value of the next outermost loop
  1041.                           counter onto the stack (i.e.,2 nested 
  1042.                           loops).
  1043.  
  1044.              I-          Subtract the value of the innermost counter
  1045.                          from the value on the stack.
  1046.  
  1047.              I+          Add the value of the innermost counter to
  1048.                           the value on the stack.
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.         USING FORTH                                             Page 2-15
  1059.  
  1060.  
  1061.  
  1062.  
  1063.              Consider a loop to print the numbers from 1 to 10:
  1064.  
  1065.                   OK :  10_#'S 11 1 DO I .  LOOP ; <cr>
  1066.  
  1067.         When executed, 10_#'S will give
  1068.  
  1069.                   OK 10_#'S <cr>
  1070.                   1 2 3 4 5 6 7 8 9 10
  1071.                   OK
  1072.  
  1073.  
  1074.              Since  DO  expects to find the iteration parameters  on  the 
  1075.         stack at execution time,  you can wait until then to define them. 
  1076.         A general, ascending order, number printing routine might be:
  1077.  
  1078.                   OK :  GEN_ASC_ORD DO I .  LOOP ; <cr>
  1079.  
  1080.         When executed, this word expects to find the DO parameters on the 
  1081.         stack:
  1082.  
  1083.                   OK 11 1 GEN_ASC_ORD <cr>
  1084.                   1 2 3 4 5 6 7 8 9 10
  1085.                   OK
  1086.  
  1087.              Since  one  normally thinks of these parameters  as  [start] 
  1088.         [finish] rather than the order that DO prefers, and further since 
  1089.         [finish] is often preferred over [finish+1], try this:
  1090.  
  1091.                   :  LIMITS 1+ SWAP ;  
  1092.  
  1093.         The  1+ adds 1 to [finish] and SWAP puts [start] and [finish]  in 
  1094.         the correct order for a DO.   In other words,  you have created a 
  1095.         "preprocessor"  for  DO-LOOPS.   This is rarely  done  with  most 
  1096.         languages,  but  if  you  expect  to use this  a  few  times  the 
  1097.         convenience pays off in FORTH.
  1098.  
  1099.                   OK :  GEN_#_PRINT LIMITS DO I .  LOOP ; <cr>
  1100.  
  1101.         In use, this gives:
  1102.  
  1103.                   OK 1 5 GEN_#_PRINT <cr>
  1104.                   1 2 3 4 5 
  1105.                   OK
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.         USING FORTH                                             Page 2-16
  1125.  
  1126.  
  1127.         2.11.2  Conditional branching
  1128.  
  1129.  
  1130.              Conditionals traditionally allow some value to be tested and 
  1131.         a  branch to occur based upon the test.   FORTH  allows  one- and 
  1132.         two-sided conditional branches.
  1133.  
  1134.              The  IF word and the THEN word are the simplest  cases.   IF 
  1135.         will  cause  the  definitions  between it  and  THEN  to  execute 
  1136.         provided  the top stack value (TOS) is logical true  (or  really, 
  1137.         not  equal  to zero).   If the TOS is zero,  FORTH will  skip  to 
  1138.         execute the words following the THEN word.  For example,
  1139.  
  1140.                   OK :  USE_IF IF 1 .  THEN 2 .  ;  <cr>
  1141.  
  1142.         When executed, this definition will give
  1143.  
  1144.                   OK 1 USE_IF <cr>
  1145.                   1 2
  1146.                   OK 0 USE_IF <cr>
  1147.                   2
  1148.                   OK
  1149.  
  1150.         IF always removes the logical quantity it tests from the stack.
  1151.  
  1152.              Another word,  ELSE, allows one of two branches to be taken. 
  1153.         As an example:
  1154.  
  1155.                   OK :  USE_ELSE IF 1 .  ELSE 0 .  THEN ;  <cr>
  1156.  
  1157.              If 0 is on the stack,  the ELSE-clause will be executed;  if 
  1158.         a  number other than 0 is on the stack,  the TRUE-clause will  be 
  1159.         executed, as in
  1160.  
  1161.                   OK 0 USE_ELSE <cr>
  1162.                   0
  1163.                   OK 4 USE_ELSE <cr>
  1164.                   1
  1165.                   OK
  1166.  
  1167.         The ELSE portion executes if TOS is false, or 0.  In either case, 
  1168.         the  definition after THEN executes.   In the preceding  example, 
  1169.         the compiler operator ";" will execute.   It will signal both the 
  1170.         end of the definition at compile time, and perform house-cleaning 
  1171.         at the end of the definition at execute time.
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.         USING FORTH                                             Page 2-17
  1191.  
  1192.  
  1193.         2.11.3  Block structure branching
  1194.  
  1195.  
  1196.              FORTH also provides a block structure which is essentially a 
  1197.         loop without an iteration counter.  It is of the form:
  1198.  
  1199.                   BEGIN [good stuff] [flag] UNTIL
  1200.  
  1201.              BEGIN  is  a  place holder and marks the  beginning  of  the 
  1202.         block.   UNTIL tests for a true or false TOS, and if false trans-
  1203.         fers  back to the word following BEGIN.   If true,  the word fol-
  1204.         lowing UNTIL will execute.   UNTIL will remove its logical  quan-
  1205.         tity from the stack.
  1206.  
  1207.  
  1208.         2.12  And so Forth....
  1209.  
  1210.  
  1211.              You  now have seen most of the basics of FORTH,  along  with 
  1212.         some  examples.   The best way to learn more at this stage is  to 
  1213.         sit at a terminal and practice!
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.         USING FORTH                                             Page 2-1
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.                                     Chapter 3
  1263.  
  1264.                            UNIQUE FEATURES OF UNIFORTH
  1265.  
  1266.  
  1267.                 As  mentioned  earlier,  the Sampler is a subset  of  our 
  1268.         commercial FORTH.  Even so, it has many additions to the FORTH-83 
  1269.         standard.  This chapter will mention a few of those features.  We 
  1270.         recommend  the  purchase  of  the UNIFORTH Manual  Set  for  more 
  1271.         information.
  1272.  
  1273.  
  1274.         3.1  Files
  1275.  
  1276.  
  1277.              UNIFORTH uses DOS 2 tree-structured files.   In other words, 
  1278.         you can access files in any directory on any disk from inside  of 
  1279.         UNIFORTH.  The limitation is that the file pathname cannot exceed 
  1280.         63 characters.
  1281.  
  1282.              When  first  invoking  UNIFORTH,  you  have  the  option  of 
  1283.         including  a  file  name on the same line.   If no  name  follows 
  1284.         UNIFORTH,  then file FORTH.FTH will be  opened.   Otherwise,  the 
  1285.         passed file will be opened.  For example,
  1286.  
  1287.                        UNIFORTH TEST.BIN
  1288.  
  1289.         will  open file TEST.BIN for access after the coldstart procedure 
  1290.         is completed.
  1291.  
  1292.              All UNIFORTH source code filenames have an extension of .FTH 
  1293.         for unique identification.
  1294.  
  1295.              The following words give the basic file access functions:
  1296.  
  1297.              CHANA,CHANB
  1298.                   There  are  two default "channels" for file  access  in 
  1299.                   UNIFORTH,  selected by the words CHANA and CHANB.  When 
  1300.                   first  invoking UNIFORTH,  CHANA is assumed.   After  a 
  1301.                   channel has been selected, all file read/write commands 
  1302.                   are  directed  to that channel.   If  you  now  specify 
  1303.                   CHANB,  all  commands are directed to the file open  on 
  1304.                   that channel.
  1305.  
  1306.              MAKE-CHAN <name>
  1307.                   If  you  want more files to be open  concurrently,  you 
  1308.                   might  want to add channels.   This word will create  a 
  1309.                   new word like CHANA that,  when executed, switches file 
  1310.                   commands  to a new channel.   Each channel occupies  64 
  1311.                   bytes  of  dictionary  space in addition  to  the  word 
  1312.                   header.
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.         UNIQUE FEATURES OF UNIFORTH                        Page 3-2
  1323.  
  1324.  
  1325.  
  1326.              OPEN <fname>
  1327.                   Open the file.   If the file doesn't exist, you will be 
  1328.                   prompted for its creation.   If you decline to create a 
  1329.                   new file, the previous file will be reopened.
  1330.  
  1331.              CLOSE
  1332.                   Close  the file on the current channel.   No action  is 
  1333.                   taken if a file is not currently open.
  1334.  
  1335.              MAKE <fname>
  1336.                   You can explicitly create a file with this word.   MAKE 
  1337.                   and OPEN only create the DOS directory entry;  the file 
  1338.                   has  no length until you explicitly write data  to  it.  
  1339.                   Also,  until you close the file,  DOS does not know the 
  1340.                   file's length.
  1341.  
  1342.              DELETE <fname>
  1343.                   Deletes the file.
  1344.  
  1345.              FILESTATUS
  1346.                   Displays information about the currently open file.
  1347.  
  1348.              Once opened, a file can be accessed in one of two ways:
  1349.  
  1350.              (1)  As  a block-oriented (FORTH) file.   You read/write  to 
  1351.                   the file using 1024-byte random-access blocks of  data.  
  1352.                   Common words are BLOCK, BUFFER, UPDATE, LOAD, etc.
  1353.  
  1354.              (2)  As a sequential, text-oriented file.  You read/write to 
  1355.                   the file in bytes or lines,  where a line is terminated 
  1356.                   with  a  CR/LF pair of ASCII characters.   This is  the 
  1357.                   kind of file created by EDLIN or WORDSTAR.
  1358.  
  1359.              Block-oriented  files are the most straightforward.   All of 
  1360.         the  FORTH-83  read/write/load words work on  block  files.   The 
  1361.         limitations are that you will get an error message if you try  to 
  1362.         access data beyond the end of the file,  and that you cannot load 
  1363.         block  0  of any file.   You can also open and read binary  files 
  1364.         such as UNIFORTH.COM with BLOCK, and dump their contents.
  1365.  
  1366.              A blank file can be created,  or a current file extended  in 
  1367.         length,  using  the word EXTEND.   It has the number of blocks to 
  1368.         extend as its argument.   Each added block is blank-filled with a 
  1369.         ";S" at the beginning.
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.         UNIQUE FEATURES OF UNIFORTH                        Page 3-3
  1389.  
  1390.  
  1391.              You can move blocks from one file to another with a brace of 
  1392.         words:
  1393.  
  1394.              n1 n2 COPYATOB
  1395.                   Copy  block n1 of the file currently open on channel  A 
  1396.                   into block n2 of channel B.
  1397.  
  1398.  
  1399.              n1 n2 #blks MCOPY
  1400.                   Copy #blks starting at block n1 in channel A to channel 
  1401.                   B, starting at block n2.
  1402.  
  1403.              Text files are read byte-by-byte.   You should not use BLOCK 
  1404.         on a text file, as there is no guarantee that the file will be an 
  1405.         exact multiple of 1024 bytes in length (meaning you won't be able 
  1406.         to access the last part of the file).  Instead, there is a set of 
  1407.         words to perform the major read/write operations for you.
  1408.  
  1409.              RDBYTE char
  1410.                   Read one byte from the current file.  If the end of the 
  1411.                   file  is  reached,  leave a true flag in place  of  the 
  1412.                   character.
  1413.  
  1414.              adr cnt handle READ-BYTES nchar
  1415.                   Read  several  bytes  from a file into a  buffer  (like 
  1416.                   EXPECT).   Leave on the stack the number of  characters 
  1417.                   actually read, or 0 if an eof was detected.
  1418.  
  1419.              adr cnt RDLINE nchar
  1420.                   Read a "line" from the file into a buffer.   The number 
  1421.                   of  characters actually read (nchar) will be less  than 
  1422.                   cnt if a CR/LF is detected.
  1423.  
  1424.              char WRBYTE
  1425.                   Write the character to the current file.
  1426.  
  1427.              adr cnt handle WRITE-BYTES nchar
  1428.                   Write  cnt  characters  to  the  file  pointed  to   by 
  1429.                   "handle".   nchar  is  the actual number of  characters 
  1430.                   written,  and will be less than cnt only if the disk is 
  1431.                   full.
  1432.  
  1433.              adr cnt WRLINE
  1434.                   Write  cnt characters to the current  file.   Append  a 
  1435.                   CR/LF pair to terminate the line.
  1436.  
  1437.              WREOF
  1438.                   Write an end-of-file mark on the current file.
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.         UNIQUE FEATURES OF UNIFORTH                        Page 3-4
  1455.  
  1456.  
  1457.              d1 meth handle !FILE-POS d2
  1458.                   A   method  of  random-access  on  a  sequential  file.  
  1459.                   Position  the  next read/write to byte d1 of  the  file 
  1460.                   pointed  to  by handle.   The position  method  can  be 
  1461.                   absolute (0),  relative (1) or past the end of the file 
  1462.                   (2).  d2 is the new location of the file pointer.
  1463.  
  1464.              handle @FILE-POS d1
  1465.                   Returns  the current file pointer (double integer bytes 
  1466.                   from beginning of file).
  1467.  
  1468.         The  "handle" on some of these words is the MSDOS handle  number.  
  1469.         It is returned when you open a file.   The current channel's name 
  1470.         is pointed to by variable FCB, and the first byte of that name is 
  1471.         the handle.   For example, to get the handle for the file open on 
  1472.         channel A:
  1473.  
  1474.                   CHANA FCB @ C@
  1475.  
  1476.         will do the trick.
  1477.  
  1478.              You  can  also  load source code  from  a  text  file.   For 
  1479.         example,  you might like to use FRED as a basic text editor,  and 
  1480.         feel  restricted by the 12x64 format of a FORTH block.   You  can 
  1481.         create a text file and load the entire file:
  1482.  
  1483.              TLOAD
  1484.                   Load  the  currently  open text file  starting  at  the 
  1485.                   current file pointer.  Each line of text is interpreted 
  1486.                   just  as if you had entered it from the  console.   You 
  1487.                   must terminate the file with a ;S.
  1488.  
  1489.         Loading  from  a  text  file requires a  minimum  of  three  disk 
  1490.         buffers, so check #BUFF before you attempt a load.
  1491.  
  1492.  
  1493.         3.2  Vectored I/O
  1494.  
  1495.  
  1496.              UNIFORTH  permits up to three input devices and five  output 
  1497.         devices to be used for console I/O.  These devices are controlled 
  1498.         by  the low-order byte of variable IOBYTE.   Each bit is assigned 
  1499.         to  a  particular  input  or  output  device.    By  setting  the 
  1500.         appropriate bit,  you can send output to 5 devices simultaneously 
  1501.         or select an alternate keyboard.
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.         UNIQUE FEATURES OF UNIFORTH                        Page 3-5
  1521.  
  1522.  
  1523.              A 16-byte table is located at IOBYTE+2.   The bits in IOBYTE 
  1524.         select from these 8 addresses to execute the proper routine.  The 
  1525.         bit definitions are:
  1526.  
  1527.                   bit#      IOTAB+...      routine
  1528.                   0         2              PC-specific input
  1529.                   1         4              console input
  1530.                   2         8              user specified input routine
  1531.                   3         10             user specified output routine
  1532.                   4         12             console output
  1533.                   5         14             disk output
  1534.                   6         16             printer output
  1535.                   7         18             PC-specific output
  1536.  
  1537.                             20             PC-specific status
  1538.                             22             console status
  1539.                             26             user specified status
  1540.  
  1541.         For  example,  to select console input and  printer  output,  you 
  1542.         would  set  IOBYTE to 42H.   You can insert your own routines  in 
  1543.         this table, with restrictions.  Check the Professional Manual Set 
  1544.         for more information.
  1545.  
  1546.              We've defined a set of words to account for the most  common 
  1547.         combinations:
  1548.  
  1549.                   TERMINAL       select PC input and output
  1550.                   PRINTER        select printer output only
  1551.                   +PRINTER       add printer output to current selection
  1552.                   +DISK          add disk output to current selection
  1553.  
  1554.         The  disk output is very restricted.   You must have a text  file 
  1555.         open  on  channel B.   All terminal output is then stored on  the 
  1556.         text file (a log file if you will).
  1557.  
  1558.  
  1559.         3.3  Numeric input
  1560.  
  1561.  
  1562.              The  UNIFORTH  Sampler  supports  three  basic  data  types:  
  1563.         single  precision (16-bit) integers,  double  precision  (32-bit) 
  1564.         integers, and single precision (32-bit) floating point.
  1565.  
  1566.              When  entering  a number from the keyboard,  you  must  tell 
  1567.         FORTH  what  type  of  number it is  to  convert.   Since  16-bit 
  1568.         integers are the default,  you need only enter the digits with an 
  1569.         optional  +  or - sign at the beginning.   For  32-bit  integers, 
  1570.         include a comma anywhere within the number.   For floating point, 
  1571.         include a period anywhere within the number, with an optional "E" 
  1572.         style exponent.  Examples:
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.         UNIQUE FEATURES OF UNIFORTH                        Page 3-6
  1587.  
  1588.  
  1589.                   string         converted as:
  1590.                   235            16-bit integer 
  1591.                   23,5           32-bit integer
  1592.                   235.0          floating point
  1593.                   2.35E2         floating point
  1594.  
  1595.         All values convert to 235.   Variable PRECIS tells you what  kind 
  1596.         of  number  was  last  converted  (-1=none,  0=16-bit,  1=32-bit, 
  1597.         2=floating point),  and variable DPL locates the decimal point or 
  1598.         comma within the number.
  1599.  
  1600.  
  1601.         3.4  Video editor
  1602.  
  1603.  
  1604.              We've  included our "slow" video editor as part of the basic 
  1605.         system.   It  comes preconfigured for the IBM PC,  and uses  only 
  1606.         BIOS calls to perform its duties.   We suggest that clone  owners 
  1607.         try  this editor as-is before attempting any  modifications.   At 
  1608.         worst, the screen will be filled with garbage characters, and you 
  1609.         can  exit  the  editor  at  any  time  with  ctrl-X  without  any 
  1610.         modifications  being written to disk (or ESC if changes are to be 
  1611.         written).
  1612.  
  1613.              To enter the editor,  just use "n EDIT" where n is the block 
  1614.         number to be edited.   If you were attempting to load a block and 
  1615.         ran  into  an error,  and received the  block/line  number  error 
  1616.         message,  the word WHERE (no arguments) will enact the editor and 
  1617.         display  the  erroneous  code.   UNIFORTH  automatically  selects 
  1618.         between the monochrome and the color graphics cards,  and between 
  1619.         old  and new PC's,  so the editor should work without problem  on 
  1620.         almost every system.
  1621.  
  1622.              Once  inside  the  editor,  the commands  are  pretty  self-
  1623.         explanatory.  All commands are mnemonic related and are displayed 
  1624.         at the top of the screen.   The line stack is a temporary holding 
  1625.         area  that  can  be  used to transfer lines  from  one  block  to 
  1626.         another.   Jump  block will position the cursor at the  displayed 
  1627.         block number; overtype it with the block you wish to move to.
  1628.  
  1629.              If   you  wish  to  customize  the  editor,   look  at  file 
  1630.         VEDITOR.FTH.   It  contains configuration blocks for three  other 
  1631.         popular terminals:   the ADM3/5,  the H-19 and the  VT-100.   The 
  1632.         UNIFORTH  Professional  version includes about 10  more  terminal 
  1633.         types.  However, this basic selection will cover 95% of all clone 
  1634.         cases.   Find  the  terminal type that most closely matches  your 
  1635.         system  and  load  the  appropriate  block.   This  modifies  the 
  1636.         vectored editor words that are terminal specific.
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.         UNIQUE FEATURES OF UNIFORTH                        Page 3-7
  1653.  
  1654.  
  1655.              In  addition,  all control codes are defined  as  constants.  
  1656.         You  may  wish  to use another key (such as  a  WordStar  layout) 
  1657.         instead  of  what we've selected.   Just modify  the  appropriate 
  1658.         parameter   and   menu  item  from  VEDITOR.FTH  and   load   the 
  1659.         configuration block.
  1660.  
  1661.              When you've made all of the necessary changes, resysgen your 
  1662.         system to save the modifications.
  1663.  
  1664.  
  1665.         3.5  SYSGEN
  1666.  
  1667.  
  1668.              UNIFORTH permits the storage of a precompiled system,  to be 
  1669.         later executed in a similar manner as UNIFORTH.COM.   You may add 
  1670.         anything  to the system that you want;  make patches to the basic 
  1671.         system;  delete  earlier utilities like the  high-level  floating 
  1672.         point  functions;  and then save the new task image onto  another 
  1673.         file.
  1674.  
  1675.              The SYSGEN utility is in file FORTH.FTH.   You will find two 
  1676.         words most useful:
  1677.  
  1678.              REALLOCATE
  1679.                   This  word  prompts you for two pieces of  information:  
  1680.                   the  number of disk buffers and the  memory  size.   We 
  1681.                   recommend  3  buffers.   If you have more than 64Kb  of 
  1682.                   user program space on your system (that is,  more  than 
  1683.                   about 96Kb of total memory),  you may be tempted to use 
  1684.                   a  number  larger than 64 when asked for  memory  size.  
  1685.                   The  UNIFORTH  Sampler is limited to 64K,  and so  will 
  1686.                   truncate  any  answer  you give  to  fit  within  those 
  1687.                   constraints.
  1688.  
  1689.              SYSGEN
  1690.                   The main word.   After you have used reallocate, sysgen 
  1691.                   will  save  the compiled image onto a task  file.   You 
  1692.                   specify the file name.
  1693.  
  1694.              SCRAMBLE
  1695.                   If you wish to distribute a commercial application  and 
  1696.                   don't  want  the user to have any access to  FORTH,  we 
  1697.                   recommend  the  use of the  word  SCRAMBLE.   It  first 
  1698.                   destroys  the word links,  then executes  SYSGEN.   The 
  1699.                   resultant  compiled task image will not be able to find 
  1700.                   enough words in the dictionary to make effective use of 
  1701.                   FORTH,  yet your later application words will still  be 
  1702.                   available.
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.         UNIQUE FEATURES OF UNIFORTH                        Page 3-8
  1719.  
  1720.  
  1721.         3.6  Assembler
  1722.  
  1723.  
  1724.              Included  in UNIFORTH.COM is an assembler that uses the 8086 
  1725.         mnemonics.   This assembler is essential in defining some of  the 
  1726.         basic words of the system, and uses some 3K bytes of storage.
  1727.  
  1728.              You have full access to this assembler for your own use and, 
  1729.         in fact, are highly encouraged to use it.  FORTH machine language 
  1730.         definitions are extremely easy to create and debug, compared with 
  1731.         other  languages.   It  is ideal for learning how to  program  in 
  1732.         machine language, or to test out various algorithms before incor-
  1733.         porating them in other programs.
  1734.  
  1735.              Machine language FORTH words are created by using one of the 
  1736.         defining words CODE or SUBROUTINE.  In each case, the interpreta-
  1737.         tion state is changed from compilation (i.e.,storing the  addres-
  1738.         ses  of routines into a definition) to execution (executing  each 
  1739.         word as it is encountered).  The words executed are 8086 opcodes, 
  1740.         which  use stack parameters to create 8086 instructions which are 
  1741.         then stored into the definition.
  1742.  
  1743.  
  1744.         3.6.1  Creation of Code Words
  1745.  
  1746.  
  1747.              To create a machine-language word callable from other  FORTH 
  1748.         words,  use CODE,  just like you would the defining word "colon". 
  1749.         For example,
  1750.  
  1751.              CODE DUP  DX POP,  DX PUSH,  DX PUSH,  NEXT,  END-CODE
  1752.  
  1753.         which  creates  a  code word called DUP that pops the  top  stack 
  1754.         value  into the register DX,  then pushes it back on  twice.  The 
  1755.         last  statement  in  a CODE definition must  be  END-CODE,  which 
  1756.         cleans up the stack and returns the user to the FORTH vocabulary.
  1757.  
  1758.              The word NEXT, is one of the three required ways of termina-
  1759.         ting the actual word definition if the new word is to be callable 
  1760.         from other FORTH words.  The three ways are:
  1761.  
  1762.                   NEXT,     Jump  to the interpreter to pick up the  next 
  1763.                             word to execute.
  1764.  
  1765.                   APUSH,    Push  the  contents of AX onto the stack  and 
  1766.                             then jump to the interpreter (go to NEXT).
  1767.  
  1768.                   DPUSH,    Push the contents of DX onto the stack,  then 
  1769.                             push AX, and finally go to NEXT.
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.         UNIQUE FEATURES OF UNIFORTH                        Page 3-9
  1785.  
  1786.  
  1787.  
  1788.              A  defining  word called SUBROUTINE is available  to  create 
  1789.         machine-language  words  to  be used only  within  other  machine 
  1790.         language words (using CALLs or JMPs).  For example,
  1791.  
  1792.              SUBROUTINE 4*  AX AX ADD,  AX AX ADD,  RET,  END-CODE
  1793.  
  1794.         creates  the  word 4* that will multiply AX by 4.   To  use  this 
  1795.         word:
  1796.  
  1797.              CODE 64*  AX POP,  4* CALL,  4* CALL,  4* CALL,
  1798.                APUSH,  END-CODE
  1799.  
  1800.         will multiply the top stack value by 64.   Remember:   you cannot 
  1801.         directly execute 4* as defined in this way.  For example,
  1802.  
  1803.              : 64*  4* 4* 4* ;
  1804.  
  1805.         will leave three copies of the PFA of 4* on the stack, instead of 
  1806.         performing the desired multiplication.
  1807.  
  1808.              The  data  stack is accessed by the "PUSH," and "POP,"  8086 
  1809.         instructions.   All FORTH return stack operations are not  easily 
  1810.         accessible from inside CODE words.   Also,  because push, pop and 
  1811.         call  use  the  data stack,  you must be careful on how  to  pass 
  1812.         arguments  to subroutines as the arguments to be passed  will  be 
  1813.         covered  up by a "call" type statement unless you first pop  them 
  1814.         into registers in the calling routine.
  1815.  
  1816.              The 8086 registers are assigned by UNIFORTH as follows:
  1817.  
  1818.                   AX   general purpose register 
  1819.                   BX   general purpose register, also used by NEXT 
  1820.                   CX   general purpose register 
  1821.                   DX   general purpose register 
  1822.                   DI   general purpose register 
  1823.                   SI   the interpreter pointer, IP
  1824.                   BP   the FORTH "return stack", RP
  1825.                   SP   data stack pointer
  1826.                   CS   segment register.  Must be preserved
  1827.                   DS   segment register.  Must be preserved
  1828.                   SS   segment register.  Must be preserved
  1829.                   ES   temp seg register.  Only used by a few words.
  1830.  
  1831.         Any register labelled as general purpose can be used at any  time 
  1832.         by  any word.   Other registers can be used by the programmer  if 
  1833.         their contents are saved and restored.   DX is only used by ;CODE 
  1834.         and  can generally be used by the programmer as a general purpose 
  1835.         register.  DI may be used in future versions for storing the user 
  1836.         area pointer, so use it with caution in your applications.
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.         UNIQUE FEATURES OF UNIFORTH                        Page 3-10
  1851.  
  1852.  
  1853.              Here are some other points that may save you some grief.  As 
  1854.         shown  in  the  register assignment table,  SI is  used  for  the 
  1855.         interpreter  pointer.   String operations such as MOVS use SI  as 
  1856.         the  source address register.   Remember to save SI,  perform the 
  1857.         operation,  and then restore SI.  The UNIFORTH Sampler sets all 4 
  1858.         segment  registers equal.   You should therefore set DS=ES on all 
  1859.         string operations by a sequence similar to:
  1860.  
  1861.                        DS AX MOV,
  1862.                        AX ES MOV,
  1863.  
  1864.         (you can't MOVe directly between segment registers).   The  inner 
  1865.         interpreter,  NEXT,  assumes  that  the direction flag  has  been 
  1866.         cleared.  If you use STD in a word, be sure you reset it with CLD 
  1867.         before jumping to NEXT.
  1868.  
  1869.              The opcode mnemonics used in the assembler are basically the 
  1870.         same as used by Intel, except:
  1871.  
  1872.              1.  All instructions are reverse-polish.  For example,
  1873.  
  1874.                            Intel:  MOV CL,AH
  1875.  
  1876.                            FORTH:  AH CL MOV,
  1877.  
  1878.  
  1879.              2.   All instructions have a trailing comma.  This indicates 
  1880.                   that something is being stored in the dictionary by the 
  1881.                   instruction,  and also prevents multiple definitions as 
  1882.                   would be the case for XOR.
  1883.  
  1884.              3.   The calls,  unconditional jumps,  and returns have been 
  1885.                   divided into intrasegment versions (CALL, JMP, RET) and 
  1886.                   "long" intersegment versions (LCALL,LJMP,LRET).
  1887.  
  1888.              4.   The normal prefixes such as LOCK,  SEG, REP, BYTE, WORD 
  1889.                   are  coded  without  any suffixed  comma.   All  string 
  1890.                   operations assume byte mode unless overridden.
  1891.  
  1892.              5.   The assembler is definitely not user-proof.   The  only 
  1893.                   error  checking  is for removal of all items placed  on 
  1894.                   the stack during the definition (i.e.,  loops and bran-
  1895.                   ches properly terminated).  You, as the programmer, are 
  1896.                   responsible   for   knowing  proper   usage   of   each 
  1897.                   instruction.
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.         UNIQUE FEATURES OF UNIFORTH                        Page 3-11
  1917.  
  1918.  
  1919.                                     NOTATION
  1920.  
  1921.         reg       any of the registers as appropriate
  1922.         cc        condition codes such as Z,NZ,CY,NC,GT,LT,LE,MI
  1923.         data      an 8-bit integer
  1924.         data16    a 16-bit integer
  1925.         addr      a 16-bit address
  1926.         addr32    a 32-bit address
  1927.         disp      a signed 8-bit displacement
  1928.         disp16    a signed 16-bit displacement
  1929.  
  1930.  
  1931.         Addressing modes:
  1932.  
  1933.              Intel                     FORTH
  1934.              MOV  AX,BX               BX AX MOV,
  1935.              MOV  AX,[DI]             [DI] AX MOV,
  1936.              MOV  AX,[BP+4]           4 [BP+] AX MOV,
  1937.              MOV  AX,[BP+DI]          [BP+DI] AX MOV,
  1938.              MOV  AX,[BP+DI+4]        4 [BP+DI+] AX MOV,
  1939.              MOV  AX,[4000]           4000 ) AX MOV,
  1940.              MOV  AX,32               32 # AX MOV,
  1941.  
  1942.         Instruction Specifics:
  1943.  
  1944.              Intel                    FORTH
  1945.              CALL addr32              addr32 LCALL,
  1946.              CALL disp16              addr CALL,
  1947.              REP BYTE CMPS            REP BYTE CMPS,
  1948.              ESC mem                  mem ESC,
  1949.              IN AX,32                 32  AX IN,
  1950.              INT  21                  21 INT,
  1951.              JMP addr32               addr32 LJMP,
  1952.              JMP  disp                addr JMP,
  1953.              LOOP disp                addr LOOP,
  1954.              RCL  AX,1                1 # AX RCL,
  1955.              RET disp16               disp16 RET,
  1956.              RET disp16               disp16 LRET,
  1957.              SEG  ES                  ES SEG,
  1958.  
  1959.         where  addr  is the actual address to which you  want  to  branch 
  1960.         (UNIFORTH calculates the appropriate offset).
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.         UNIQUE FEATURES OF UNIFORTH                        Page 3-12
  1983.  
  1984.  
  1985.         13.6.2  Conditional Branching
  1986.  
  1987.  
  1988.              Several  branching structures have been included as in  high 
  1989.         level FORTH.   You can use IFs and BEGIN-UNTIL loops, in addition 
  1990.         to hard branching with JMP-style opcodes.
  1991.  
  1992.           cc IF,       Start a forward branch.   cc is the 8086 condition 
  1993.                        code  to be satisfied.   (Actually,  IF,  codes  a 
  1994.                        conditional jump of the opposite sense of cc).
  1995.  
  1996.           ELSE,        The branch for the case when the condition code is 
  1997.                        not satisfied.
  1998.  
  1999.           THEN,        Termination of an IF, statement.
  2000.  
  2001.           BEGIN,       Start of a block structure.
  2002.  
  2003.           cc UNTIL,    Branches back to BEGIN, until cc is satisfied.
  2004.  
  2005.           cc WHILE,    Executes   statements   following  while   cc   is 
  2006.                        satisfied.
  2007.  
  2008.           REPEAT,      End of a BEGIN, WHILE, sequence.
  2009.  
  2010.           DO,          Mark  the  beginning of a DO-LOOP.   Identical  to 
  2011.                        BEGIN,
  2012.  
  2013.  
  2014.         In each case of a conditional testing instruction,  you must have 
  2015.         set  or tested the condition codes before the instruction  execu-
  2016.         tion.   For example,  for 'NZ IF,' you could have executed 'BL AH 
  2017.         CMP,' before the IF, to set the condition codes.  Also, since the 
  2018.         conditionals  use the Intel conditional  jump  instructions,  all 
  2019.         branching must be less than 128 bytes in length.
  2020.  
  2021.  
  2022.         3.6.3  Examples
  2023.  
  2024.  
  2025.              Some of the best examples of CODE words can be found in your 
  2026.         library  disk.   Listed  below  are three simple  examples  as  a 
  2027.         further guide.
  2028.  
  2029.              For  more help in programming the 8086,  we highly recommend 
  2030.         the purchase of The 8086 Book, by Russel Rector and George Alexy, 
  2031.         Osborne  Press,  or The 8086 Primer,  by  Stephen  Morse,  Hayden 
  2032.         Press.
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.         UNIQUE FEATURES OF UNIFORTH                        Page 3-13
  2049.  
  2050.  
  2051.         Example  1.   Incrementing  the top stack value by the amount  in 
  2052.         variable INCREASE.
  2053.  
  2054.              VARIABLE INCREASE         ( initial value)
  2055.              2 INCREASE !     
  2056.           
  2057.              CODE BUMP                 ( define BUMP)
  2058.                  AX POP,               ( pop stack value into AX)
  2059.                  INCREASE ) DX MOV,    ( get increment into DX)
  2060.                  DX AX ADD,            ( add together)
  2061.                  APUSH,                ( put total back on stack)
  2062.                  END-CODE
  2063.  
  2064.         Example  2.   Adding  or subtracting 1 from the top  stack  value 
  2065.         depending on whether it is positive or negative respectively.
  2066.  
  2067.              CODE BIGGER               ( define BIGGER)
  2068.                   DX POP,              ( pop stack value into DX)
  2069.                   AX AX XOR,           ( clear AX)
  2070.                   DX AX CMP,           ( is value negative)
  2071.                   LT IF,               ( if LT, yes)
  2072.                   AX DEC,              (   so then subtract)
  2073.                   ELSE,                ( if not GT, then...)
  2074.                   AX INC,              (   increment)
  2075.                   THEN,                ( now end)
  2076.                   APUSH,               ( by pushing AX onto stack)
  2077.                   END-CODE
  2078.  
  2079.         Example 3.   Using a DO-LOOP construct with DO and LOOP.  Shift a 
  2080.         byte left n times.
  2081.  
  2082.              CODE LSHIFT               ( define LSHIFT)
  2083.                   CX POP,              ( get count)
  2084.                   AX POP,              ( byte to shift is now in AL)
  2085.                   DO,                  ( start of loop)
  2086.                   1 # AL ROL,          ( rotate left one bit)
  2087.                   LOOP,                ( continue until CX=0)
  2088.                   APUSH,               ( put rotated value back
  2089.                   END-CODE             (   on stack and end)
  2090.  
  2091.  
  2092.  
  2093.         3.7  Segment Utility
  2094.  
  2095.              A  short  utility  can be found  in  FORTH.FTH  that  allows 
  2096.         reading  and writing of data into the entire 1Mb address space of 
  2097.         the  8088.   The  utility can use either long  (32-bit)  absolute 
  2098.         addresses (in which case, the words are prefixed with an "L"), or 
  2099.         segment/offset addresses (words prefixed with "SEG").
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.         UNIQUE FEATURES OF UNIFORTH                        Page 3-14
  2115.  
  2116.  
  2117.              seg adr SEG@ n
  2118.                   Fetch the 16-bit value located at seg:adr.
  2119.  
  2120.              seg adr SEGC@ n
  2121.                   Fetch the 8-bit value located at seg:adr.
  2122.  
  2123.              n seg adr SEG!
  2124.                   Store the 16-bit value n at address seg:adr.
  2125.  
  2126.              n seg adr SEGC!
  2127.                   Store the 8-bit value n at address seg:adr.
  2128.  
  2129.              seg1 adr1 seg2 adr2 cnt SEGCMOVE
  2130.                   Move cnt bytes from seg1:adr1 to seg2:adr2.   Count has 
  2131.                   a maximum value of 64K-max(adr1,adr2).
  2132.  
  2133.              dadr L@ n
  2134.                   Fetch the 16-bit value located at address dadr.
  2135.  
  2136.              dadr LC@ n
  2137.                   Fetch the 8-bit value located at address dadr.
  2138.  
  2139.              n dadr L!
  2140.                   Store the 16-bit value n at address dadr.
  2141.  
  2142.              n dadr LC!
  2143.                   Store the 8-bit value n at address dadr.
  2144.  
  2145.              dadr1 dadr2 cnt LCMOVE
  2146.                   Move cnt bytes from dadr1 to dadr2.   Cnt has a maximum 
  2147.                   value of 64K.
  2148.  
  2149.              MYSEG val
  2150.                   Leave  on the stack the current segment number for  the 
  2151.                   code space (that is, CS).
  2152.  
  2153.              dadr ADR>SEG seg adr
  2154.                   Convert the 32-bit address into a segment number and  a 
  2155.                   16-bit offset.
  2156.  
  2157.              seg adr SEG>ADR dadr
  2158.                   Convert the seg:adr address into a 32-bit address.
  2159.  
  2160.  
  2161.         3.8  Deviations from FORTH-83
  2162.  
  2163.  
  2164.              We've sold FORTH-79 systems for years, but took 18 months to 
  2165.         decide to revise UNIFORTH to match the FORTH-83 Standard.   There 
  2166.         has been a lot of controversy about F83, with good reason.
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.         UNIQUE FEATURES OF UNIFORTH                        Page 3-15
  2181.  
  2182.  
  2183.              The primary problem is that FIG-FORTH and F79 programs  will 
  2184.         not  run  under F83.   The Standards committee changed the  basic 
  2185.         function of several words,  but kept their names the same.   This 
  2186.         means that the wealth of published FORTH software is not  useable 
  2187.         without recoding, so beware!
  2188.  
  2189.              UNIFORTH closely follows F83 with some exceptions.   Primary 
  2190.         amongst  these is the F83 requirement of floored division.   What 
  2191.         this  means  is  that integer truncation is  to  the  next  lower 
  2192.         number.   Dividing  -14  by 10 yields -2,  since  the  fractional 
  2193.         result   is   -1.4.    This  type  of  truncation   makes   sense 
  2194.         mathmatically  but  doesn't match your natural thinking  nor  the 
  2195.         currently available hardware.   All 8086,  68000,  PDP-11, Z8000, 
  2196.         etc.  processors  use  arithmetic where the result  is  truncated 
  2197.         towards zero.   Our example would then yield -1 as the result.
  2198.  
  2199.              Another  problem  is in handling the sign of the  remainder.  
  2200.         If you divide -14 by 10, is the remainder -4 or +4?  F83 requires 
  2201.         that  the  result by +4 (taking the sign of  the  divisor).   All 
  2202.         processors give remainders that use the sign of the dividend,  or 
  2203.         -4 in our example.  Again, UNIFORTH conforms to the hardware, not 
  2204.         the Standard.
  2205.  
  2206.              We've  left  many  words "immediate" (such  as  ."  and  all 
  2207.         vocabulary names).  F83 uses separate words for execution and for 
  2208.         compile.    F83's  UM*  is  UNIFORTH's  USS*D,   where  our  form 
  2209.         explicitly  tells  what  kind of mixed mode arithmetic  is  being 
  2210.         used.
  2211.  
  2212.              We're  not happy about the -1 truth flag.   While  it  makes 
  2213.         sense logically,  it makes error checking more difficult.  Beware 
  2214.         of F79 and FIG-FORTH uses of the truth flag!
  2215.  
  2216.              The  Programmer's Guide gives information on how to  convert 
  2217.         FIG-FORTH and F79 systems to UNIFORTH.
  2218.  
  2219.              There  is  much  more  about the Sampler  that  hasn't  been 
  2220.         discussed here.   Explore the system!  You may find features that 
  2221.         are of use.   The Manual Set describes the UNIFORTH  Professional 
  2222.         in  gory detail,  so you might take a look at it if you need more 
  2223.         help.
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.         UNIQUE FEATURES OF UNIFORTH                        Page 3-1
  2247.  
  2248.  
  2249.  
  2250.  
  2251.                                     Chapter 4
  2252.  
  2253.                               WHAT YOU ARE MISSING
  2254.  
  2255.  
  2256.              Now that you have used UNIFORTH,  you might be interested in 
  2257.         how the Professional differs from the public domain Sampler.   We 
  2258.         recommend  writing  for our free,  complete catalog,  but  listed 
  2259.         below are some of the major differences in more technical detail.
  2260.  
  2261.         Multitasking
  2262.              The Professional is a fast multitasking system.   Tasks  can 
  2263.         be assigned priorities,  and messages can be passed between them.  
  2264.         Each  task  takes less than 1K bytes of memory,  so many  can  be 
  2265.         resident  at once.   We often build systems that include the user 
  2266.         task,  a  printer spooler,  a temperature background  acquisition 
  2267.         task,  and  a  telecommunications task,  where all  four  are  in 
  2268.         operation at once at no noticible degradation in response.
  2269.  
  2270.         Speed
  2271.              We've carefully optimized the Professional and use state-of-
  2272.         the-art  threading techniques to make the fastest possible  FORTH 
  2273.         system.   The  floating  point routines use a separate stack  for 
  2274.         fastest calculations.   You will find a 50% or larger improvement 
  2275.         in speed.
  2276.  
  2277.         Strings
  2278.              A full string package is included.   All the functions  that 
  2279.         you would find in BASIC,  such as MID$ and INSTR, are included so 
  2280.         that you can manipulate strings as easily as integers.
  2281.  
  2282.         Custom utilities
  2283.              The IBM PC Professional UNIFORTH includes files of functions 
  2284.         to access the keyboard, provide full musical note generation, and 
  2285.         to  draw  lines,  dots and filled polygons on the color  graphics 
  2286.         board.  In addition, every DOS2 system request is implemented.
  2287.  
  2288.         The fast video editor
  2289.              An  improved  video editor is included,  that  accesses  the 
  2290.         video memory directly.   Screens appear as fast on the screen  as 
  2291.         your  disk access will let them.   Extra functions such as multi-
  2292.         file editing,  line split and paste,  and adding blank blocks are 
  2293.         included.
  2294.  
  2295.         Source code
  2296.              You get the source code to everything except the 5Kb kernel.  
  2297.         In all, about 400Kb of source code is distributed.
  2298.  
  2299.         Debugger
  2300.              The  Professional  comes with a single-step  debugger/tracer 
  2301.         that can be used to track down errors in your code.  The data and 
  2302.         return  stacks  are displayed as each word  is  executed.   Break 
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.         WHAT YOU ARE MISSING                               Page 4-2
  2313.  
  2314.  
  2315.         points may be set.
  2316.  
  2317.         Decompiler
  2318.              A  complete decompiler will display any high-level  UNIFORTH 
  2319.         word on your screen.   This utility is highly useful to check the 
  2320.         syntax of a word or to retrieve an interactive definition.
  2321.  
  2322.         More systems
  2323.              The   Professional   UNIFORTH  is  available  for  a   dozen 
  2324.         processors and even more operating systems.  We will customize it 
  2325.         for  a particular computer,  create stand-alone systems  and  add 
  2326.         multi-user support as desired.
  2327.  
  2328.         Floating point
  2329.              Both hardware and software floating point is included.   The 
  2330.         hardware  floating  point uses the 8087,  gives both  single  and 
  2331.         double precision capability,  and provides some really impressive 
  2332.         speed gains.   Of course,  all opcode extensions to the assembler 
  2333.         are included.
  2334.  
  2335.         Documentation
  2336.              The   UNIFORTH  Professional  comes  with  500+   pages   of 
  2337.         documentation in a custom slipcase/binder.   All aspects of FORTH 
  2338.         are covered,  from a tutorial much like the one in this manual to 
  2339.         detailed   discussions   of   threading   techniques,    database 
  2340.         management,  forms generation,  coding conventions and much more.  
  2341.         Numerous examples are included to speed the learning process.
  2342.  
  2343.         Support
  2344.              You get 90 days of free hotline support.  Additional support 
  2345.         is also available.   We offer on-site classes.   The Professional 
  2346.         is offered with a 30-day money-back guarantee.
  2347.  
  2348.         Cross-compilers
  2349.              The  UNIFORTH cross-compiler requires the Professional,  and 
  2350.         supports many microprocessor targets.
  2351.  
  2352.              For  complete  information,  write  for  the  free  UNIFORTH 
  2353.         catalog.   If  you  just wish to order an MS/PCDOS  version  that 
  2354.         corresponds to this Sampler,  then use the catalog numbers listed 
  2355.         below.
  2356.  
  2357.         Cat #          Computer                      Price
  2358.         M22       Generic MSDOS 2.x                  $245
  2359.         M22P      IBM PC/XT/Jr DOS 2.x               $245
  2360.         M22T      TI Professional MSDOS 2.x          $245
  2361.         M22R      Rainbow 100 MSDOS 2.x              $245
  2362.         M22A      IBM PC/AT 80286 specific DOS 3.x   $295
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.         WHAT YOU ARE MISSING                               Page 4-3
  2379.  
  2380.  
  2381.         Other items of interest are listed below.
  2382.  
  2383.         Cat #          Sampler version               Price
  2384.         S21Z      Z80 CP/M 2.2                       $35
  2385.         S21P      IBM PC DOS 2.x                     $35
  2386.         S21A      Apple // (ProDos, 80col)      coming soon
  2387.         S21C      Commodore 64                  coming soon
  2388.         S21M      Macintosh                     coming soon
  2389.  
  2390.         Cat #          Item                          Price
  2391.         BK01      UNIFORTH Manual Set                $60
  2392.         BK11      Starting FORTH/Brodie              $17.95
  2393.         BK12      Thinking FORTH/Brodie              $15.95
  2394.  
  2395.  
  2396.         Ordering information:
  2397.  
  2398.              Specify your computer type and your disk format.   All items 
  2399.         are sent post-paid by UPS or First Class within the U.S.  Checks, 
  2400.         CODs,  money  orders  and purchase orders  in  U.S.  dollars  are 
  2401.         accepted.  Maryland residents add 5% sales tax.  Prices are valid 
  2402.         as of April 15,  1985 and may be different if ordering much later 
  2403.         than that date.  Make checks payable to:
  2404.  
  2405.                             Unified Software Systems
  2406.                                   P.O. Box 2644
  2407.                             New Carrollton, MD 20784
  2408.                                  (301) 552-9590
  2409.  
  2410.  
  2411.         Conclusions
  2412.  
  2413.              We  hope  that you have enjoyed using the UNIFORTH  Sampler.  
  2414.         It is a complete FORTH system that will provide you many years of 
  2415.         usefulness.   Please, let us know your impressions.  Did you find 
  2416.         FORTH worthwhile?   Are there bugs in this system?  What features 
  2417.         would  you  like to see?   Its through user input  and  community 
  2418.         discussion that FORTH will grow or die.  Cast your vote!
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444. ommunity 
  2445.         discussion that FORTH will grow or die.  Cast your vote!
  2446.